package com.lsf.modules.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lsf.common.api.CommonApi;
import com.lsf.common.constant.CacheConstant;
import com.lsf.modules.base.vo.LoginUser;
import com.lsf.modules.base.vo.PermissionDataRuleModel;
import com.lsf.modules.base.vo.UserCacheInfo;
import com.lsf.modules.system.entity.Permission;
import com.lsf.modules.system.entity.PermissionDataRule;
import com.lsf.modules.system.entity.User;
import com.lsf.modules.system.mapper.PermissionMapper;
import com.lsf.modules.system.mapper.UserMapper;
import com.lsf.modules.system.mapper.UserRoleMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 底层通用业务API
 *
 * @author Alexander
 */
@Service
public class BaseApiImpl implements CommonApi {

    @Resource
    private UserMapper userMapper;

    @Resource
    private UserRoleMapper userRoleMapper;

    @Resource
    private PermissionMapper permissionMapper;

    @Override
    public Set<String> queryUserRoles(String username) {
        return null;
    }

    @Override
    public Set<String> queryUserAuths(String username) {
        return null;
    }

    @Override
    @Cacheable(cacheNames = CacheConstant.SYS_USERS_CACHE, key = "#username")
    public LoginUser getUserByName(String username) {
        if (StringUtils.isEmpty(username)) {
            return null;
        }
        LoginUser loginUser = new LoginUser();
        User user = userMapper.getUserByName(username);
        if (user == null) {
            return null;
        }
        BeanUtils.copyProperties(user, loginUser);
        return loginUser;
    }

    @Override
    public LoginUser getUserById(String id) {
        if (StringUtils.isNotEmpty(id)) {
            LoginUser loginUser = new LoginUser();
            User user = userMapper.selectById(id);
            if (user != null) {
                BeanUtils.copyProperties(user, loginUser);
                return loginUser;
            }
        }
        return null;
    }

    @Override
    public List<String> getRolesByName(String username) {
        return null;
    }

    @Override
    public List<PermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username) {
        return null;
    }

    @Override
    public JSONObject queryAllUser(String userIds, Integer pageNo, Integer pageSize) {
        return null;
    }

    @Override
    public List<String> getRoleIdsByName(String username) {
        return null;
    }

    @Override
    public Set<String> getUserRoleSet(String username) {
        return null;
    }

    @Override
    public Set<String> getUserPermissionSet(String username) {
        return null;
    }
}
